package com.business.action.platform;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import net.sf.rose.jdbc.DBUtils;
import net.sf.rose.jdbc.PageBean;
import net.sf.rose.jdbc.bean.FieldBean;
import net.sf.rose.jdbc.service.Service;

@Controller
@RequestMapping("/plat/field")
public class FieldAction {

	/**
	 * 
	 */
	@ResponseBody
	@RequestMapping("/list.do")
	public PageBean list(HttpServletRequest request, Service service, String tableID) {
		PageBean page = new PageBean();
		page.setData(DBUtils.getBeanListByKey(service, FieldBean.class, "tableID", tableID));
		return page;
	}

	/**
	 * 
	 */
	@ResponseBody
	@RequestMapping("/get.do")
	public PageBean get(HttpServletRequest request, Service service, String fieldID) {
		PageBean page = new PageBean();
		FieldBean bean = DBUtils.getBean(service, FieldBean.class, fieldID);
		page.setData(bean);
		return page;
	}

	/**
	 * 
	 */
	@ResponseBody
	@RequestMapping("/save.do")
	public PageBean save(HttpServletRequest request, Service service, FieldBean bean) {
		PageBean res = new PageBean();
		/*Map<String, DataTypeBean> types = service.getDataTypeMap();
		DataTypeBean t = types.get(bean.getType());
		bean.setDbType(t.getDbType()); // 数据库数据类型
		bean.setJavaType(t.getJavaType());// Java数据类型
*/		if (DBUtils.update(service, bean) > 0) {
			res.setMessage("保存信息成功！");
		} else {
			res.setSuccess(false);
			res.setMessage("保存信息失败！");
		}
		return res;
	}

	/**
	 * 删除
	 */
	@ResponseBody
	@RequestMapping("/delete.do")
	public PageBean delete(HttpServletRequest request, Service service, String fieldID) {
		return DBUtils.delete(service, FieldBean.class, fieldID);
	}
}
